package com.yuyou.fn.educational.service.impl;

import com.github.wens.mybatisplus.examples.Example;
import org.apache.commons.lang3.StringUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.yuyou.fn.educational.mapper.CourseTypeMapper;
import com.yuyou.fn.educational.entity.CourseType;
import com.yuyou.fn.educational.service.ICourseTypeService;
import com.github.wens.framework.service.impl.SuperServiceImpl;

import java.util.List;

/**
 *
 * CourseType 表数据服务层接口实现类
 *
 */
@Service
public class CourseTypeServiceImpl extends SuperServiceImpl<CourseTypeMapper, CourseType,Long> implements ICourseTypeService {


    @Override
    public String findCourseTypeNameById(Long courseTypeId) {

        Example<CourseType> example = CourseType.createExample();
        example.selectProperties("name");
        example.createCriteria().andEqualTo("courseTypeId",courseTypeId);
        CourseType courseType = findOneByExample(example);

        return courseType == null ? StringUtils.EMPTY : courseType.getName() ;
    }


    @Cacheable("cacheOfCourseTypeList")
    @Override
    public List<CourseType> findAllCourseTypeFromCache() {
        Example<CourseType> example = CourseType.createExample();
        return findListByExample(example);
    }

    @Override
    public CourseType findCourseTypeByName(String courseTypeName) {
        Example<CourseType> example = CourseType.createExample();
        example.createCriteria().andEqualTo("name",courseTypeName);
        return  findOneByExample(example);
    }
}